import 'package:flutter/material.dart';
import 'dart:convert';
enum ResMsgType {
  createRoom,
  enterRoom,
  otherEnterRoom,
  otherOutRoom,
  dealCard,
  statusChange,
  landlord,
  gameEnd,
  invite,
  updateMagnification,
  setOtherRoleStatus,
  updateMsgCount,
  userInfo
}
enum SendMsgType {
  loginout,
  enterRoom,
  ready,
  cancelReady,
  outRoom,
  readyCards,
  callLandlord,
  notLandlord,
  robLandlord,
  notRobLandlord,
  openHand,
  playCards,
  invite,
  restart
}
class SocketMsg {
  static List<String> sendMsgStr = ['loginout', 'enterRoom','ready','cancelReady','outRoom','readyCards','callLandlord','notLandlord','robLandlord','notRobLandlord','openHand','playCards','invite','restart'];
  static Map<String,ResMsgType> resMsgTypeFromStr = {'createRoom':ResMsgType.createRoom,'enterRoom':ResMsgType.enterRoom,'otherEnterRoom':ResMsgType.otherEnterRoom
      ,'otherOutRoom':ResMsgType.otherOutRoom,'dealCard':ResMsgType.dealCard,'statusChange':ResMsgType.statusChange,'landlord':ResMsgType.landlord,'gameEnd':ResMsgType.gameEnd,
      'invite':ResMsgType.invite,'updateMagnification':ResMsgType.updateMagnification,'setOtherRoleStatus':ResMsgType.setOtherRoleStatus,'updateMsgCount':ResMsgType.updateMsgCount,'userInfo':ResMsgType.userInfo,};
  final SendMsgType type;
  Map data;

  SocketMsg({@required this.type, this.data});

  @override
  String toString() {
    return '{"type":"'+sendMsgStr[this.type.index]+'"'+(data==null?'':',"data":'+json.encode(data))+'}';
    // String res = '{"type":"'+sendMsgStr[this.type.index]+'"';
    // String dataStr = "";
    // if(this.data != null) {
    //   this.data.forEach((key, val){
    //     dataStr += ',"'+key.toString()+'":'+valToString(val);
    //   });
    // }
    
    // if(dataStr.length > 0) {
    //   res += ','+'"data":{'+dataStr.substring(1)+'}';
    // }
    // res += '}';
    // return res;
  }
}